package com.seanLab.web;

import com.seanLab.domain.Body;
import com.seanLab.dto.FeedbackDto.EditorAddTagDto;
import com.seanLab.dto.FeedbackDto.EditorDeleteTagDto;
import com.seanLab.dto.FeedbackDto.EditorFeedbackDto;
import com.seanLab.dto.FeedbackDto.EditorImageScoreDto;
import com.seanLab.dto.RecommendArticleDto;
import com.seanLab.service.FeedbackService;
import com.seanLab.tool.validator.DtoValidator;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

/**
 * Created by ailly on 17-9-22.
 */
@CrossOrigin(origins = "*", maxAge = 3600)
@RestController
@RequestMapping("/v1/editor")
public class FeedbackController {
    @Autowired
    private FeedbackService feedbackService;

    @Autowired
    private DtoValidator dtoValidator;

    //选择图片接口
    @RequestMapping(path = "/feedbacks", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
    public Body insertEditorFeedback(@RequestBody EditorFeedbackDto editorFeedbackDto, @RequestHeader HttpHeaders headers) {
        int errorCode = dtoValidator.validateAuthorization(headers.getFirst("App-ID"), headers.getFirst("App-Key"));
        if (0 == errorCode) {
            Body body = this.feedbackService.addFeedback(editorFeedbackDto);
            return body;
        } else {
            return Body.getResponseBody(errorCode);
        }

    }

    //新增标签接口
    @RequestMapping(path = "/addTags", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
    public Body insertEditorAddTag(@RequestBody EditorAddTagDto editorFeedbackDto) {
        Body body = this.feedbackService.addTag(editorFeedbackDto);
        return body;
    }

    //删除标签接口
    @RequestMapping(path = "/deleteTags", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
    public Body insertEditorDeleteTag(@RequestBody EditorDeleteTagDto editorFeedbackDto) {
        Body body = this.feedbackService.deleteTag(editorFeedbackDto);
        return body;
    }

    //图片评分接口
    @RequestMapping(path = "/score", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
    public Body insertEditorFeedback(@RequestBody EditorImageScoreDto editorFeedbackDto) {
        Body body = this.feedbackService.addImgScore(editorFeedbackDto);
        return body;
    }

}
